package classes.view
{
	import classes.OX_Application;
	import classes.view.component.SingleRoom;
	
	import flash.events.Event;
	
	import flashx.textLayout.elements.BreakElement;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class Mediator_SingleRoom extends Mediator implements IMediator
	{
		public static const NAME:String = "Mediator_SingleRoom";
		public function Mediator_SingleRoom(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			init();
		}
		override public function listNotificationInterests():Array
		{
			return [OX_Application.READY_SCREEN,
					OX_Application.SINGLE_ROOM_START,
					OX_Application.SINGLE_GAME_PAUSE,
					OX_Application.SINGLE_ROOM_OFF,
					OX_Application.SINGLE_RE_ON];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName()){
				case OX_Application.READY_SCREEN :
					if(notification.getBody() == false){
						singleRoom.startgame();
					}
					break;
				case OX_Application.SINGLE_ROOM_START :
					singleRoom.singleroom_switch = true; 
					break;
				case OX_Application.SINGLE_GAME_PAUSE :
					if(notification.getBody() == 'resume'){
						singleRoom.startBool = false;	
					}
					break;
				case OX_Application.SINGLE_ROOM_OFF :
					singleRoom.singleroom_switch = false;
					break;
				case OX_Application.SINGLE_RE_ON :
					singleRoom.single_restart();
					break;
			}
		}
		private function init():void
		{
			singleRoom.addEventListener("ShowReadyScreen",			singleGameEvent);
			singleRoom.addEventListener("singleGameOver",			singleGameEvent);
			singleRoom.addEventListener('goList',					singleGameEvent);
			singleRoom.addEventListener('pauseIN',					singleGameEvent);
			singleRoom.addEventListener('popup_setting_incorrect',	singleGameEvent);
			singleRoom.addEventListener('popup_setting',			singleGameEvent);
		}
		private function singleGameEvent(e:Event):void
		{
			switch(e.type){
				case "ShowReadyScreen" :
					sendNotification(OX_Application.READY_SCREEN, 			true);
					break;
				case "goList" :
					sendNotification(OX_Application.SINGLE_GAME_OVER, 		'singleList');
					break;
				case "singleGameOver" :
					sendNotification(OX_Application.SINGLE_GAME_OVER, 		'singleScore');
					break;
				case "pauseIN" :
					sendNotification(OX_Application.SINGLE_GAME_PAUSE, 		'pause');
					break;
				case "popup_setting_incorrect" :
					sendNotification(OX_Application.SINGLE_POPUP_INCORRECT);
					break;
				case "popup_setting" :
					sendNotification(OX_Application.SINGLE_POPUP_SETTING);
					break;
			}
		}
		
		protected function get singleRoom():SingleRoom
		{
			return viewComponent as SingleRoom;
		}
	}
}